<template>
  <div>
    <x-header :left-options="{showBack: false}" theme="">审核信息</x-header>
    <msg :title="success?'审核通过':'审核不通过'" :buttons="success?suc_buttons:warn_buttons" :icon="success?suc_icon:warn_icon">
      <div class="error_info" slot="description">
        <p style="padding-bottom: 10px">{{time}}</p>
        <div class="error_row" v-for="list in errors" :key="list" v-if="!success">
          <div class="error_col error_col_span_3">
            <i slot="icon" class="iconfont icon-warning_fill" style="color:#ea5a49;font-size: 20px"></i>
          </div>
          <div class="error_col error_col_span_9" style="padding: 5px 0">
            {{list}}
          </div>
        </div>
      </div>
    </msg>
  </div>
</template>
<script>
  import {XHeader, Msg} from 'Vux'
  export default {
    components: {
      XHeader,
      Msg
    },
    data(){
      return {
        title: "错误信息",
        success: false,
        time: null,
        suc_icon: "success",
        description: "内容详情，可根据实际需要安排，如果换行则不超过规定长度，居中展现",
        suc_buttons: [
          {
            type: 'primary',
            text: '生产电子计划书',
            onClick: this.createPlan.bind(this)
          }, {
            type: 'default',
            text: '返回主页',
            onClick: this.goBack.bind(this)
          }
        ],
        warn_icon: "warn",
        warn_buttons: [
          {
            type: 'primary',
            text: '修改信息',
            onClick: this.editedInfo.bind(this)
          }, {
            type: 'default',
            text: '返回主页',
            onClick: this.goBack.bind(this)
          }
        ],
        submitRiskNo: null,
        errors: []
      }
    },
    methods: {
      createPlan(){
        this.$vux.loading.show('计划书生成中..');
        setTimeout(() => {
          this.$vux.loading.hide();
          this.$router.push('/pdf');
          this.$store.commit('CHANGE_TRANSITION', 'left')
        }, 2000)
      },
      delete(){
        let obj = {
          body: {
            riskAssessNO: this.submitRiskNo
          }
        };
        $.ajax("../ui/servlet/GCASServlet/deleteRisk", {
          method: "post",
          contentType: "text/json;charset=UTF-8",
          data: JSON.stringify(obj),
          success: () => {

          },
          error: () => {

          }
        });
      },
      editedInfo(){
        this.delete();
        this.$router.push('/inquiry');
        this.$store.commit('CHANGE_TRANSITION', 'right')
      },
      goBack(){
        this.$router.push('/home');
        this.$store.dispatch('initForm');
        this.$store.commit('CHANGE_TRANSITION', 'right')
      }
    },
    mounted(){
      this.success = this.$store.state.app.submitFlag;
      this.submitRiskNo = this.$store.state.app.submitRiskNo;
      let failedNotes = this.$store.state.app.submitFailedNotes;
      if(failedNotes){
        let errors = [];
        for(let i=0;i<failedNotes.length;i++){
          errors.push(failedNotes[i].rereviewedNote)
        }
        this.errors = errors
      }
      let time = new Date();
      this.time = time.toLocaleString()
    }
    ,
    destroyed(){
      this.$store.commit('REMOVE_SUBMIT_FLAG')
    }
  }
</script>
<style scoped>
  .button-error {
    background-color: #ff5847;
    color: white;
  }

  .resultIcon {
    margin-top: 150px;
  }

  .result {
    text-align: center;
  }

  .resultFlag {
    font-size: 1.3rem;
    margin-top: 10px;
  }

  .resultTime {
    font-size: 14px;
    margin-top: 10px;
    color: #ddd
  }

  .error_info {
    text-align: center;
  }

  .error_row {
    position: relative;
    margin-left: 0;
    margin-right: 0;
    height: auto;
    zoom: 1;
    display: block;
    padding: 2px 0;
  }

  .error_col {
    display: block;
    float: left;
    -ms-flex: 0 0 auto;
    -webkit-box-flex: 0;
    flex: 0 0 auto;
  }

  .error_row:after, .error_row:before {
    content: "";
    display: table;
  }

  .error_row:after {
    clear: both;
    visibility: hidden;
    font-size: 0;
    height: 0;
  }

  .error_col_span_3 {
    text-align: left;
    width: 10%;
  }

  .error_col_span_9 {
    color: #808080;
    text-align: left;
    width: 90%;
  }
</style>
